<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>事件监听</title>
</head>
<body>
    <input type="button" id="btnOk" value="确认" />

    <script type="text/javascript">
        //事件监听
        /*
        var a = document.getElementById("btnOk");
        a.onclick = function(){            
            alert("这是一个操作");
        }
        */

        //事件监听，更利于代码复用
        function ShowMsg(){
            alert("这是一个操作");
        }
        var a = document.getElementById("btnOk");
        a.addEventListener("click", ShowMsg, false);
    </script>
</body>
</html>